import request from '@/utils/request'
import { limit } from '@/consts/consts'
const devUrl = process.env.VUE_APP_ENV === 'production' ? `http://${window.location.host}/dev` : 'dev'

export default {
  // 4.3.1 获取设备类型列表
  deviceTypeList(data) {
    if (!data.limit) {
      data.limit = limit
    }
    return request({
      url: `${devUrl}/api/v1/devices/collection/list`,
      method: 'get',
      params: data
    })
  },
  // 4.3.2 新增设备类型
  // device_type name meta_device_id sketch disable m_category s_category open_way close_way
  deviceTypeAdd(data) {
    return request.post(`${devUrl}/api/v1/devices/collection/add`, {
      data: data
    })
  },
  // 4.3.3 修改设备类型
  deviceTypeUpdate(collectId, data) {
    return request.put(`${devUrl}/api/v1/devices/collection/update/${collectId}`, {
      data: data
    })
  },
  // 4.3.4 删除设备类型
  deviceTypeDelete(collectId) {
    return request({
      url: `${devUrl}/api/v1/devices/collection/delete/${collectId}`,
      method: 'delete'
    })
  },

  // 4.4.1、获取设备列表
  devicesList(params) {
    return request({
      url: `${devUrl}/api/v1/devices/list`,
      method: 'get',
      params
    })
  },

  // 4.4.2、新增设备
  deviceAdd(data) {
    return request.post(`${devUrl}/api/v1/devices/add`, data)
  },
  // 4.4.3、删除设备
  deviceDelete(devId) {
    return request.delete(`${devUrl}/api/v1/devices/delete/${devId}`)
  },
  // 4.4.4、根据设备类型获取设备列表
  deviceByType({ type, limit, offset }) {
    return request.get(`${devUrl}/api/v1/devices/type/list?type=${type}&offset=${offset}&limit=${limit}`)
  },
  // 4.4.6、修改设备
  deviceUpdate({ deviceId, ...rest }) {
    return request.put(`${devUrl}/api/v1/devices/update/${deviceId}`, rest)
  },
  // 4.4.8、获取设备详情
  deviceDetails(devId) {
    return request.get(`${devUrl}/api/v1/devices/detail/${devId}`)
  },
  // 4.4.14、根据分支和设备类型获取设备列表
  deviceByBranchType({ branch, type, offset, limit }) {
    if (!offset) {
      offset = 0
    }
    return request.get(`${devUrl}/api/v1/devices/branch/device-type/list?branch=${branch}&device_type=${type}&offset=${offset}&limit=${limit}`)
  },

  // 4.4.20、根据分支、设备类型过滤
  deviceTypeListByType(data) {
    return request.post(`${devUrl}/api/v1/devices/filter/list`, data)
  },

  // 4.4.21、设置照度共享
  setAllShare(data) {
    return request.post(`${devUrl}/api/v1/devices/share`, data)
  },

  // 4.5.1 获取制造商列表
  mfList(listQuery) {
    return request({
      url: `${devUrl}/api/v1/devices/mf/list`,
      method: 'get',
      params: listQuery
    })
  },
  // 4.5.2、新增制造商
  mfAdd(paramsData) {
    return request({
      url: `${devUrl}/api/v1/devices/mf/add`,
      method: 'post',
      data: { data: paramsData }
    })
  },
  // 4.6.1、获取型号列表
  modelList(listQuery) {
    return request({
      url: `${devUrl}/api/v1/devices/model/list`,
      method: 'get',
      params: listQuery
    })
  },
  // 4.10.1、获取品牌列表
  brandList(listQuery) {
    return request({
      url: `${devUrl}/api/v1/devices/brand/list`,
      method: 'get',
      params: listQuery
    })
  },

  // 4.30.1. 获取店内设备位置
  inStoreEquipmentList(data) {
    if (!data.limit) {
      data.limit = limit
    }
    return request({
      url: `${devUrl}/api/v1/store/pos`,
      method: 'get',
      params: data
    })
  },

  // 4.7.1、获取租户设备类型列表
  collectionList(listQuery) {
    return request({
      url: `${devUrl}/api/v1/devices/tenant/collection/list`,
      method: 'get',
      params: listQuery
    })
  },
  // 4.7.2、新增租户设备类型
  collectionAdd(projectId, paramsData) {
    return request({
      url: `${devUrl}/api/v1/devices/tenant/collection/add`,
      method: 'post',
      params: { project_id: projectId },
      data: { data: paramsData }
    })
  },
  // 4.7.4、管理租户设备类型
  collectionManage(projectId, paramsData) {
    return request({
      url: `${devUrl}/api/v1/devices/tenant/collection/manage/${projectId}`,
      method: 'put',
      data: { data: paramsData }
    })
  },
  // 4.7.5、修改租户设备类型
  collectionUpdate(collectId, paramsData) {
    return request({
      url: `${devUrl}/api/v1/devices/tenant/collection/update/${collectId}`,
      method: 'put',
      data: { data: paramsData }
    })
  },

  // 4.10.1、获取品牌列表
  devicesBrandList({
    offset,
    limit = limit
  }) {
    return request.get(`${devUrl}/api/v1/devices/brand/list?offset=${offset}&limit=${limit}`)
  },
  // 4.10.2、新增品牌
  devicesBrandAdd(paramsData) {
    return request({
      url: `${devUrl}/api/v1/devices/brand/add`,
      method: 'post',
      data: { data: paramsData }
    })
  },

  // 4.6.1、获取型号列表
  devicesModelList({
    offset,
    limit = limit
  }) {
    return request.get(`${devUrl}/api/v1/devices/model/list?offset=${offset}&limit=${limit}`)
  },
  // 4.6.2、新增型号
  devicesModelAdd(paramsData) {
    return request({
      url: `${devUrl}/api/v1/devices/model/add`,
      method: 'post',
      data: { data: paramsData }
    })
  },

  // 4.11.1．查询告警列表
  alarmList(params, data) {
    return request({
      url: `${devUrl}/api/v1/devices/alarm/list`,
      method: 'post',
      params,
      data
    })
  },

  // 4.11.5、查询告警总数
  alarmCount(data) {
    return request({
      url: `${devUrl}/api/v1/devices/alarm/count`,
      method: 'post',
      data
    })
  },

  // 4.12.1、查询设备总数
  modelTotal(params) {
    return request({
      url: `${devUrl}/api/v1/devices/total`,
      method: 'get',
      params
    })
  },

  // 4.12.2、查询在线设备总数
  modelOnlineTotal(params) {
    return request({
      url: `${devUrl}/api/v1/devices/online/total`,
      method: 'get',
      params
    })
  },

  // 4.12.3、查询离线设备总数
  modelOfflineTotal(params) {
    return request({
      url: `${devUrl}/api/v1/devices/offline/total`,
      method: 'get',
      params
    })
  },

  // 4.12.4、查询告警总数
  modelAlarmTotal(projectId) {
    return request({
      url: `${devUrl}/api/v1/devices/alarm/total`,
      method: 'get',
      params: { project_id: projectId }
    })
  },

  // 4.12.5、查询门店统计
  branchStat(params) {
    return request({
      url: `${devUrl}/api/v1/devices/branch/stat`,
      method: 'get',
      params
    })
  },

  // 4.12.6、查询设备类型总数
  deviceTypeTotal(projectId) {
    return request({
      url: `${devUrl}/api/v1/devices/device-type/total`,
      method: 'get',
      params: { project_id: projectId }
    })
  },

  
  // 4.12.7、查询异常门店总数
  alarmBranchStat(params) {
    return request({
      url: `${devUrl}/api/v1/devices/alarm_branch/total`,
      method: 'get',
      params
    })
  },

  // 4.4.5    获取设备详情
  getDeviceDetail(dev_id) {
    return request({
      url: `${devUrl}/api/v1/devices/detail/${dev_id}`,
      method: 'get'
    })
  }
}
